package algorithm.poj.p3000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;


/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验和教训：
 * 
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P3366 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P3366.class.getResource("P3366.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		String[] tmp = line.trim().split(" ");
		int L = Integer.valueOf(tmp[0]);
		int N = Integer.valueOf(tmp[1]);

		Map<String, String> dic = new HashMap<String, String>();
		for (int i = 0; i < L; i ++) {
			line = stdin.readLine();
			tmp = line.trim().split(" ");
			dic.put(tmp[0], tmp[1]);
		}
		
		StringBuffer sb = new StringBuffer("");
		String word = null;
		for (int i = 0; i < N; i ++) {
			word = stdin.readLine();
			String plural = dic.get(word);
			if (plural == null) {
				if (word.endsWith("y")) {
					char c = word.charAt(word.length()-2);
					if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
						plural = word + "s";
					} else {
						plural = word.substring(0, word.length()-1) + "ies";
					}
				} else if (word.endsWith("o") || word.endsWith("s") 
						|| word.endsWith("ch") || word.endsWith("sh") || word.endsWith("x")) {
					plural = word + "es";
				} else {
					plural = word + "s";
				}
			}
			sb.append(plural).append("\n");
		}
		System.out.println(sb);
	}
	
}